var Site = {};
Site.$ = function (o) {
    return typeof o == "object" ? o : document.getElementById(o);
};
Site.Cookie = {
    set: function (name, value, sj, path, domain) {
        var expires = new Date(new Date().getTime() + sj * 3600 * 1000);
        if ((expires.getHours() + (expires.getMinutes() / 60)) < sj) {
            myDate = new Date();
            expires = new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate() + 1)
        }
        document.cookie = name + "=" + value + ((expires) ? ";expires=" + expires.toGMTString() : "") + ((path) ? ";path=" + path : "; path=/") + ((domain) ? ";domain=" + domain : "");
    },
    get: function (name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) {
            return unescape(arr[2]);
        }
        return null;
    },
    clear: function (name, path, domain) {
        if (this.get(name)) {
            document.cookie = name + "=" + ((path) ? ";path=" + path : "; path=/") + ((domain) ? ";domain=" + domain : "") + ";expires=Fri, 02-Jan-1970 00:00:00 GMT";
        }
    }
};

var XunleiKankan = {
    kkDapCtrl: null,
    kkGetDapCtrl: function () {
        if (null == XunleiKankan.kkDapCtrl) {
            try {
                if (window.ActiveXObject) {
                    XunleiKankan.kkDapCtrl = new ActiveXObject("DapCtrl.DapCtrl");
                } else {
                    var browserPlugins = navigator.plugins;
                    for (var bpi = 0; bpi < browserPlugins.length; bpi++) {
                        try {
                            if (browserPlugins[bpi].name.indexOf('Thunder DapCtrl') != -1) {
                                var e = document.createElement("object");
                                e.id = "dapctrl_history";
                                e.type = "application/x-thunder-dapctrl";
                                e.width = 0;
                                e.height = 0;
                                document.body.appendChild(e);
                                break;
                            }
                        } catch (e) {
                        }
                    }
                    XunleiKankan.kkDapCtrl = document.getElementById('dapctrl_history');
                }
            } catch (e) {
            }
        }
        return XunleiKankan.kkDapCtrl;
    },
    kkis: function () {
        try {
            var dapCtrl = new ActiveXObject("DapCtrl.DapCtrl");
            if (typeof(dapCtrl) != "undefined") {
                //var iType = dapCtrl.Get("IXMPPACKAGETYPE");
                ver = dapCtrl.GetThunderVer("KANKAN", "INSTALL");
            } else {
                return false;
            }
        } catch (e) {
            return false;
        }
        var type = dapCtrl.Get("IXMPPACKAGETYPE");
        if (type && ver && ver > 229 && (type == 2401 || type > 3000)) {
            return true;
        }
        return false;
    },
    kkPlay: function (url, cid, moviename) {
        //var dapVersion = 0;
        var ver = 0;
        try {
            var dapCtrl = new ActiveXObject("DapCtrl.DapCtrl");
            if (typeof(dapCtrl) != "undefined") {
                //var iType = dapCtrl.Get("IXMPPACKAGETYPE");
                ver = dapCtrl.GetThunderVer("KANKAN", "INSTALL");
            } else {
                dapCtrl = null;
            }
        } catch (e) {
            dapCtrl = null;
        }
        var moviename_lower = moviename.toLocaleLowerCase();
        if (moviename_lower != moviename) {
            url = url.replace(/\&moviename\=[\d\D]*$/g, "&moviename=" + moviename_lower);
            moviename = moviename_lower;
        }
        //var ext = moviename.substr(moviename.lastIndexOf('.') + 1);
        var type = dapCtrl.Get("IXMPPACKAGETYPE");
        if (type && ver && ver > 229 && (type == 2401 || type > 3000)) {
            dapCtrl.Put("sXmpArg", '"' + url + '"' + " /sname " + '"' + title + '"' + ' /sstartfrom web_xunbo' + ' /sopenfrom web_xunbo');
        }
        return true;
    },
    start: function (url) {
        var dapCtrl = XunleiKankan.kkGetDapCtrl();
        try {
            var ver = dapCtrl.GetThunderVer("KANKAN", "INSTALL");
            var type = dapCtrl.Get("IXMPPACKAGETYPE");
            if (ver && type && ver >= 672 && type >= 2401) {
                dapCtrl.Put("sXmp4Arg", '"' + url + '"' + ' /sstartfrom _web_xunbo /sopenfrom web_xunbo');
            } else {
                alert('请先更新迅雷看看播放器,然后刷新本页面！');
            }
        } catch (e) {
            alert('请先安装迅雷看看播放器,然后刷新本页面！');
        }
    }
};